<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/pub/include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>工单管理--<c:choose><c:when test="${empty workorderEntity}">添加工单</c:when><c:otherwise>编辑工单</c:otherwise></c:choose></title>
    <link href="<%=request.getContextPath() %>/css/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.form.js"></script>
    <script type="text/javascript">
        var   certifile = '';

        function mydownload(){
            certifile = $("#certifile").val();

            alert("地址："+certifile);
            if(certifile == null || certifile ==''){
                alert('下载地址为空,请上传文件');
            }else{
                location = certifile;
            }

        }

        function upload(){
            var url = getRootPath()+"/source/upload";


            var mydata = document.getElementById("myfile").files[0];
//            alert('mydata'+mydata);
            formData = new FormData();
            formData.append("myfile", mydata);

            $.ajax({
                url: url,
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                },
                success:function(returndata){

                    if(returndata.data.suc){
                        alert("上传成功");
                        document.getElementById( "myfile").style.display= "none";
                        document.getElementById( "uploadbutton").style.display= "none";
                        document.getElementById( "certifile").value = returndata.data.message;
                        certifile = returndata.data.message;
                        document.getElementById( "download").style.display= "block";

                    }else{
                        alert(returndata.data.message);
                    }
                }
            });
        }

        var   decfile = '';
        function mydownload1(){
            decfile = $("#decfile").val();
//            alert("地址："+outdescriptionTr);
            if(decfile == null || decfile ==''){
                alert('下载地址为空,请上传文件');
            }else{
                location = decfile;
            }

        }

        function upload1(){
            var url = getRootPath()+"/source/upload1";


            var mydata = document.getElementById("myfile1").files[0];
//            alert('mydata'+mydata);
            formData = new FormData();
            formData.append("myfile1", mydata);

            $.ajax({
                url: url,
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                },
                success:function(returndata){

                    if(returndata.data.suc){
                        alert("上传成功");
                        document.getElementById( "myfile1").style.display= "none";
                        document.getElementById( "uploadbutton1").style.display= "none";
                        document.getElementById( "decfile").value = returndata.data.message;
                        decfile = returndata.data.message;
                        document.getElementById( "download1").style.display= "block";

                    }else{
                        alert(returndata.data.message);
                    }
                }
            });
        }


        function firm() {
            //利用对话框返回的值 （true 或者 false）
            if (confirm("提交后将无法在更改基础信息，马上提交吗？")) {
                check();
            }
        }

        function check(){
            var url = getRootPath()+"/source/addworker?m=doadd";
            var   name = $("#name").val();
            var   projectid = $("#projectid").val();
            var   starttime = $("#starttime").val();
            var   excuttime = $("#excuttime").val();
            var   depart = $("#depart").val();
            var   status = $("#status").val();
            var certifile = $("#certifile").val();
            var decfile = $("#decfile").val();
            var   id = $("#id").val();
            if(name==""){
                alert("工单名称不能为空");
                return false;
            }
            if(projectid=="0"){
                alert("项目不能为空");
                return false;
            }
            if(depart=="0"){
                alert("部门不能为空");
                return false;
            }
            if(status==""){
                status=1;
            }
            if(decfile==""){
                alert("项目说明文件不能为空");
                return false;
            }
            <c:if test="${not empty workorderEntity}">
            url = getRootPath()+"/source/addworker?m=doedit";
            </c:if>
            var para ={
                'id' :id,
                'name':name,
                'projectid':projectid,
                'starttime' :starttime,
                'excuttime':excuttime,
                'depart':depart,
                'status':status,
                'certifile':certifile,
                'decfile':decfile
            }
//            alert(url);
            $.ajax({
                cache:false,
                type:"POST",
                url: url,
                dataType:"json",
                data:para,
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                },
                success:function(returndata){
                    alert(returndata.data.message);
                    if(returndata.data.suc){
                        window.location.href= getRootPath()+"/source/workorder?m=list";
                    }else{

                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="content">
    <jsp:include page="../pub/top.jsp"></jsp:include>
    <!--头部结束-->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="left" valign="top">
                <jsp:include page="../pub/left_source.jsp"></jsp:include>
            </td>
            <td valign="top">
                <div class="right">
                    <%--<form id="addProduceFrom" action="<c:url value="/clazz/addproduce?m=doadd"/>" method="post" onsubmit="return check(this);" style="margin:0">--%>
                    <table width="80%" border="0" cellpadding="0" cellspacing="1" bgcolor="#d1d5d8">
                        <tr>
                            <td height="28" colspan="2" bgcolor="#c6dbf8" class="biaoti" style="padding:0;">
                                <c:choose>
                                    <c:when test="${empty workorderEntity}">添加工单</c:when>
                                    <c:otherwise>编辑工单</c:otherwise>
                                </c:choose>
                            </td>
                        </tr>


                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>工单名称：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" name="name" id="name" value="<c:out value="${workorderEntity.name}" />" /></td>
                        </tr>


                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>所属项目：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="projectid" name="projectid" style="width:200px;" onchange="changeselect()">
                                    <option value="0">选择项目</option>
                                    <c:forEach items="${projectList}" var="project">
                                        <option value="${project.id}" ${project.id == workorderEntity.projectid?'selected=selected':''}><c:out value="${project.name}"/></option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7"><span>*</span>执行部门：</td>
                            <td height="28" bgcolor="#FFFFFF">
                                <select id="depart" name="depart" style="width:200px;" onchange="changeselect()">
                                    <option value="0">选择部门</option>
                                    <c:forEach items="${dapartList}" var="dapart">
                                        <option value="${dapart.code}" ${dapart.code == workorderEntity.depart?'selected=selected':''}><c:out value="${dapart.value}"/></option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">证明文件<span>(最大20M)</span>：</td>
                            <td height="28" bgcolor="#FFFFFF">

                                <input type="file" id="myfile" name="myfile" style="width:200px;" />
                                <input type="button" id="uploadbutton" name="uploadbutton" value="上传" onclick="upload()" />
                                <input type="button" name="download" id="download" value="下载" onclick="mydownload()"/>
                                <input type="hidden" name="certifile" id="certifile" style="width:200px;" value="${workorderEntity.certifile}"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">内容文件<span>(最大20M)</span>：</td>
                            <td height="28" bgcolor="#FFFFFF">

                                <input type="file" id="myfile1" name="myfile1" style="width:200px;" />
                                <input type="button" id="uploadbutton1" name="uploadbutton1" value="上传" onclick="upload1()" />
                                <input type="button" name="download1" id="download1" value="下载" onclick="mydownload1()"/>
                                <input type="hidden" name="decfile" id="decfile" style="width:200px;" value="${workorderEntity.decfile}"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">开始时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="starttime" id="starttime"  placeholder="请选择"    value="${workorderEntity.starttime}"   readonly/> <input type="button" onClick="jeDate({dateCell:'#starttime',isTime:true,format:'YYYY-MM-DD hh:mm:ss'})" value="选择时间" /></td>
                            <%--<td height="28" bgcolor="#FFFFFF"><input type="text" id="potime" name="potime" value="${projectEntity.potime}" maxlength="20" placeholder="请选择"  readonly/> <p><input type="button" onClick="jeDate({dateCell:'#potime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间"></p></td>--%>
                        </tr>
                        <tr>
                            <td width="15%" height="28" align="right" bgcolor="#edf1f7">截止时间：</td>
                            <td height="28" bgcolor="#FFFFFF"><input type="text" style="width:200px;" name="excuttime" id="excuttime"  placeholder="请选择"    value="${workorderEntity.excuttime}"   readonly/> <input type="button" onClick="jeDate({dateCell:'#excuttime',isTime:true,format:'YYYY-MM-DD hh:mm:ss'})" value="选择时间" /></td>
                            <%--<td height="28" bgcolor="#FFFFFF"><input type="text" id="potime" name="potime" value="${projectEntity.potime}" maxlength="20" placeholder="请选择"  readonly/> <p><input type="button" onClick="jeDate({dateCell:'#potime',isTime:true,format:'YYYY-MM-DD'})" value="选择时间"></p></td>--%>
                        </tr>
                        <%--<tr>--%>
                        <%--<td width="15%" height="28" align="right" bgcolor="#edf1f7">工单状态说明：</td>--%>
                        <%--<td height="28" bgcolor="#FFFFFF"><textarea  name="statustr" id="statustr" style="width:200px;height:80px;" ><c:out value="${produceEntity.description}"/></textarea></td>--%>
                        <%--</tr>--%>
                    </table>
                    <div class="anniu">
                        <p><input type="button" value="提交" class="fabu" onclick="firm()"/>
                            <c:choose>
                                <c:when test="${empty workorderEntity}"><input type="reset" value="重置" class="fabu" /></c:when>
                                <c:otherwise><input type="button" value="返回" class="fabu" onclick="history.back()" /></c:otherwise>
                            </c:choose>
                        </p>
                        <input type="hidden" name="id" id="id" value="${workorderEntity.id}"/>
                        <input type="hidden"  name="status" id="status"  value="<c:out value="${workorderEntity.status}"/>"/>
                    </div>
                    <%--</form>--%>
                </div>
                <br />
                <br />
            </td>
        </tr>
    </table>
    <jsp:include page="../pub/foot.jsp"></jsp:include>
</div>
</body>
</html>
